// components/month-picker/month-picker.js
Component({
    options: {
      multipleSlots: true, // 在组件定义时的选项中启用多slot支持
    },
    properties: {
      title: {
        type: String,
        value: "",
      },
      titleValue: {
        type: String,
        value: "",
      },
    },
    data: {
      year:new Date().getFullYear(),
      date: new Date().getMonth() + 1, // 月份选择器的选中值，初始为当前月份
    },
    methods: {
      // 日期改变触发事件
      bindDateChange(e) {
        const selectedDate = e.detail.value;
        const year = selectedDate.split("-")[0];
        const month = selectedDate.split("-")[1];
        const startTimestamp = Date.parse(selectedDate + "-01 00:00:00");
        const endTimestamp = Date.parse(year + "-" + month + "-" + new Date(year, month, 0).getDate() + " 23:59:59");
        const formattedDate = month.replace(/^0/, ""); // 格式化选中的日期，去掉前导0
  
        this.setData({
          date: formattedDate,
        });
  
        this.triggerEvent("changeDate", {
          date: formattedDate,
          startTimestamp: startTimestamp,
          endTimestamp: endTimestamp,
        });
      },
    },
  });
  